<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/4/25
 * Time: 下午3:47
 */

namespace api\modules\v1\controllers;

use common\models\User;
use yii;

class UserController extends RestController
{
    public $modelClass = 'common\models\User';


    public function actionIndex()
    {
        return [1, 2, 3];
    }
    public function actionSetUser(){
        $customer_id=Yii::$app->request->post("customer_id");
        $open_id=Yii::$app->request->post("open_id");
        $nickname=Yii::$app->request->post("nickname");
        $avatar=Yii::$app->request->post("avatar");
        $status=Yii::$app->request->post("status");
        $phone=Yii::$app->request->post("phone");
        $model=User::findOne(Yii::$app->user->id);
        if($customer_id){
            $model->customer_id=$customer_id;
        }
        if($open_id){
            $model->open_id=$open_id;
        }
        if($nickname){
            $model->nickname=$nickname;
        }
        if($avatar){
            $model->avatar=$avatar;
        }
        if($status){
            $model->status=$status;
        }
        if($phone){
            $model->phone=$phone;
        }
        $model->updated_at=time();
        if($model->save()){
            return ['code'=>1,'message'=>'保存成功'];
        }else{
            return ['code'=>0,'message'=>'保存失败','data'=>$model->getErrors()];
        }

    }

}
